package com.example.exam.tools;

import com.github.pagehelper.PageInfo;

import java.util.function.Function;
import java.util.stream.Collectors;

public class PageInfoHelper {

    /**
     * Copy map page info.
     *
     * @param <T>    the type parameter
     * @param <J>    the type parameter
     * @param source the source
     * @param mapper the mapper
     * @return the page info
     */
    public static <T, J> JsonPage<J> copyMap(JsonPage<T> source, Function<? super T, ? extends J> mapper) {
        JsonPage<J> newPage = new JsonPage<>();
//        newPage.setPageNum(source.getPageNum());
//        newPage.setSize(source.getSize());
//        newPage.setStartRow(source.getStartRow());
//        newPage.setEndRow(source.getEndRow());
        newPage.setPageSize(source.getPageSize());
        newPage.setTotal(source.getTotal());
        newPage.setPages(source.getPages());
        newPage.setList(source.getList().stream().map(mapper).collect(Collectors.toList()));
//        newPage.setPrePage(source.getPrePage());
//        newPage.setNextPage(source.getNextPage());
//        newPage.setIsFirstPage(source.isIsFirstPage());
//        newPage.setIsLastPage(source.isIsLastPage());
//        newPage.setHasPreviousPage(source.isHasPreviousPage());
//        newPage.setHasNextPage(source.isHasNextPage());
//        newPage.setNavigatePages(source.getNavigatePages());
//        newPage.setNavigatepageNums(source.getNavigatepageNums());
//        newPage.setNavigateFirstPage(source.getNavigateFirstPage());
//        newPage.setNavigateLastPage(source.getNavigateLastPage());
        return newPage;
    }
}
